#!/bin/bash
hdiutil detach /Volumes/Bootstick 2>/dev/null
hdiutil detach /Volumes/r_image 2>/dev/null
hdiutil detach /Volumes/OS\ X\ Base\ System*/ 2>/dev/null
hdiutil detach /Volumes/OS\ X\ Base\ System/ 2>/dev/null
hdiutil detach /Volumes/OS\ X\ Base\ System\ 1/ 2>/dev/null




clear
if test -e /Volumes/OS\ X\ Base\ System/
then
        echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo          found Volume OS X Base System
	echo
	echo    Remove it, or rename it. And start this tool again
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
exit
else
        echo +
fi






clear
if test -e /Volumes/OS\ X\ Base\ System*/
then
        echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo          found Volume OS X Base System
	echo
	echo    Remove it, or rename it. And start this tool again
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
exit
else
        echo ++
fi







clear
if test -e /Volumes/Bootstick/
then
        echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo          found Volume Bootstick
	echo
	echo    Remove it, or rename it. And start this tool again
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
exit
else
        echo +++
fi















clear
if test -e /Volumes/Bootstick\ */
then
        echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo          found Volume Bootstick
	echo
	echo    Remove it, or rename it. And start this tool again
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
exit
else
        echo ++++
fi







clear
if test -e ~/Desktop/Install.dmg
then

        echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo         found Install.dmg on the Desktop
	echo
	echo    Remove it, or rename it. And start this tool again
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

exit
else
        echo ++++++
fi




clear
if test -e ~/Desktop/Install.cdr
then

        echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo          found Install.cdr on the Desktop
	echo
	echo    Remove it, or rename it. And start this tool again
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

exit
else
        echo +++++++
fi






































clear
if test -e /Applications/Install\ macOS\ High\ Sierra.app
then
echo found app
else
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo /Applications/Install macOS High Sierra.app not found!
	echo
	echo Copy it into the folder Applications, and try again
	echo If you use a beta, rename it 
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
exit
fi









clear
if test -e /Applications/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/BaseSystem.dmg
then
echo found file
else
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo Install macOS High Sierra.app/Contents/SharedSupport/BaseSystem.dmg 
echo NOT FOUND
echo Check the size of the Install.app
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
exit
fi












if test -e /Applications/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/AppleDiagnostics.chunklist &&  test -e /Applications/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/AppleDiagnostics.dmg &&  test -e /Applications/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/BaseSystem.chunklist  &&  test -e /Applications/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/BaseSystem.dmg &&  test -e /Applications/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/InstallESD.dmg &&  test -e /Applications/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/InstallInfo.plist 

then 
echo okay2
else
clear
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo Some files missing in Install macOS High Sierra.app/Contents/SharedSupport
echo AppleDiagnostics.chunklist
echo AppleDiagnostics.dmg
echo BaseSystem.chunklist
echo BaseSystem.dmg
echo InstallESD.dmg 
echo InstallInfo.plist
echo 
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo THE INSTALLER IS INCOMPLETE!
echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
exit
fi












































clear
Clear

echo ================ 
echo About 5 Minutes
echo ================


 

clear
clear


echo ===================================
echo Creating Install.dmg on the Desktop
echo ===================================

hdiutil create -o ~/Desktop/Install -size 7316m -layout SPUD -fs HFS+J  
hdiutil attach ~/Desktop/Install.dmg -noverify -nobrowse -mountpoint /Volumes/r_image

clear
Clear

echo ============================
echo Restore Image to Install.dmg
echo ============================

asr restore -source /Applications/Install\ macOS\ High\ Sierra.app/Contents/SharedSupport/BaseSystem.dmg -target /Volumes/r_image -noprompt -noverify -erase



diskutil rename /Volumes/OS\ X\ Base\ System/ Bootstick

clear
clear

echo ==========================
Echo Copy Files
echo ==========================

echo ==========================
Echo This takes ABOUT 4 MINUTES
echo ==========================


mv /Volumes/Bootstick/Install\ macOS\ High\ Sierra.app /Volumes/Bootstick/Backup.app


cp -R /Applications/Install\ macOS\ High\ Sierra.app /Volumes/Bootstick/







clear 
clear 






  
mv ~/Desktop/Install.dmg  ~/Desktop/Install.cdr
 
clear 
clear 


echo ==========
Echo - DONE -
echo ==========


# by ralf.











